package com.yunhe.transfer.config;

import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.authority.Station;
import com.yunhe.common.model.authority.StationDTO;
import com.yunhe.transfer.client.AuthorityClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class StationConfig {

    @Autowired
    private AuthorityClient authorityClient;

    private static final Logger logger = LoggerFactory.getLogger(StationConfig.class);

    @Bean(name = "allStations")
    public List<Station> getStations() {
        try {
            ResultObject<List<Station>> resultObject = authorityClient.getStations(null);
            return resultObject.getResults();
        } catch (Exception e) {
            logger.error("拉取全部电站失败", e);
            return new ArrayList<>();
        }
    }
}
